#include<stdio.h>
#include<stdlib.h>
typedef struct node{
    int data;
    struct node *next;
}node;

node *createnode(int data){
    node *head=(node*)malloc(sizeof(node));
    head->data=data;
    head->next=NULL;
    return head;
}

node *mergelists(node*s1,node*s2){
    node*d=createnode(0);
    node*current=d;
    while(s1&&s2){
        if(s1->data<=s2->data){
            current->next=s1;
            s1=s1->next;
        }
        else{
            current->next=s2;
            s2=s2->next;
        }
        current=current->next;
    }
    if(s1){
        current->next=s1;
    }
    else{
        current->next=s2;
    }
    return d->next;
}

void printlist(node*head){
    if(!head){
        printf("NULL\n");
        return;
    }
    while(head){
        printf("%d",head->data);
        head=head->next;
        if(head){
            printf("\n");
        }
    }
    printf("\n");
}